class AdminController < ApplicationController
  before_filter :login_required
  before_filter :require_admin
  layout "admin/layouts/application.erb"

  def require_admin
    user_ip = request.env['REMOTE_ADDR']

    if session[:user]
      if session[:user].admin_user
        if AdminIp.find_by_admin_user_id_and_ip(session[:user].admin_user,user_ip)
          logger.debug("User #{session[:user].email} accessed admin from #{user_ip}.")
          return true
        end
        render :text => "Du försöker logga in från '#{user_ip}', detta IP är inte godkänt."
      else
        #not an admin user
      end
    else
      #not logged in
    end
    return false
  end
end
